{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "using DifferentialEquations\n",
    "using PyPlot\n",
    "using ReactionMechanismSimulator"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "phaseDict = readinput(\"../src/testing/superminimal.rms\") #load mechanism dictionary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "spcs = phaseDict[\"gas\"][\"Species\"]; #mechanism dictionaries index:  phaseDict[phasename][\"Species\" or \"Reactions\"]\n",
    "rxns = phaseDict[\"gas\"][\"Reactions\"];"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ig = IdealGas(spcs,rxns,name=\"gas\"); #Define the phase (how species thermodynamic and kinetic properties calculated)\n",
    "initialconds = Dict([\"T\"=>1000.0,\"ts\"=>[0.0,0.02,0.04,0.05],\"V\"=>[0.008314,0.01,0.012,0.012],\"H2\"=>0.67,\"O2\"=>0.33]); #Set simulation Initial Temp and Pressure\n",
    "#f(x::Float64) = 0.008314\n",
    "#initialconds = Dict([\"T\"=>1000.0,\"V\"=>f,\"H2\"=>0.67,\"O2\"=>0.33]); #Set simulation Initial Temp and Pressure\n",
    "domain,y0 = ParametrizedVDomain(phase=ig,initialconds=initialconds); #Define the domain (encodes how system thermodynamic properties calculated)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "react = Reactor(domain,y0,(0.0,0.0501)); #Create the reactor object"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "sol = solve(react.ode,DifferentialEquations.CVODE_BDF(),abstol=1e-20,reltol=1e-8); #solve the ode associated with the reactor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "bsol = Simulation(sol,domain);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plotmolefractions(bsol,0.05; t0=1e-15, N=1000, tol=0.01)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ts = exp.(range(log(1e-15),length=1000,stop=log(0.05)))\n",
    "plot(ts,[sol(t)[domain.indexes[end]] for t in ts]) #Temperature vs time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ts[argmax(diff([sol(t)[end] for t in ts]))] #Ignition Delay Time in seconds"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "getfluxdiagram(bsol,0.036,centralspecieslist=[\"OH\"],radius=5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "plotrops(bsol,\"OH\",0.01;tol=0.001)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 1.1.0",
   "language": "julia",
   "name": "julia-1.1"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "1.1.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
